package com.kuizii.demo.web.util;


import com.kuizii.demo.domain.SysUserDto;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.BeanUtils;

/**
 * Shiro工具类
 *
 * @author jameszhou
 */
public class ShiroUtil {


    /**
     * 获取当前Session中的用户
     *
     * @return
     */
    public static SysUserDto getSessionUser() {

            Subject subject = SecurityUtils.getSubject();
            if (subject != null) {
                Object object = subject.getPrincipal();
                if (object != null) {
                    SysUserDto sysUser = new SysUserDto();
                    BeanUtils.copyProperties(object, sysUser);
                    return sysUser;
                }
            }

        return null;
    }

    /**
     * 获取当前用户ID
     *
     * @return
     */
    public static String getSessionUid() {

        SysUserDto sysUser = getSessionUser();

        if (sysUser != null) {

            return sysUser.getId();
        }

        return null;
    }
}
